<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>

<xsl:template match="/">

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
	xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
	xmlns:imdb="http://www.imdb.com/imdb#">

    <xsl:for-each select="IMDb/Thing">
    
	<xsl:choose>
	
		<xsl:when test="local-name(child::*[1])='Person'">
		
			<xsl:if test="Person/@type='fictional'">
				<imdb:FictionalPerson rdf:ID="{Person/@id}">
					<imdb:Birth>
					<xsl:value-of select="Person/Birth"/>
					</imdb:Birth>
					<imdb:Name>
					<xsl:value-of select="Person/Name"/>
					</imdb:Name>
				</imdb:FictionalPerson>
				<xsl:for-each select="Person/Filmography/Self/Movie">
					<imdb:FictionalPerson rdf:about="#{../../../@id}">
						<imdb:AppearedOn rdf:resource="#{@id}"/>
					</imdb:FictionalPerson>
					<imdb:Title rdf:about="#{@id}">
						<imdb:Release><xsl:value-of select="@year"/></imdb:Release>
						<imdb:Name><xsl:value-of select="@name"/></imdb:Name>
					</imdb:Title>
				</xsl:for-each>
			</xsl:if>

			<xsl:if test="Person/@type='real'">
				<imdb:RealPerson rdf:ID="{Person/@id}">
					<imdb:Birth>
					<xsl:value-of select="Person/Birth"/>
					</imdb:Birth>
					<imdb:Name>
					<xsl:value-of select="Person/Name"/>
					</imdb:Name>
				</imdb:RealPerson>
				<xsl:for-each select="Person/Filmography/Acting/Movie">
					<imdb:RealPerson rdf:about="#{../../../@id}">
						<imdb:ActedOn rdf:resource="#{@id}"/>
					</imdb:RealPerson>
					<imdb:Title rdf:about="#{@id}">
						<imdb:Release><xsl:value-of select="@year"/></imdb:Release>
						<imdb:Name><xsl:value-of select="@name"/></imdb:Name>
					</imdb:Title>
				</xsl:for-each>

				<xsl:for-each select="Person/Filmography/Self/Movie">
					<imdb:RealPerson rdf:about="#{../../../@id}">
						<imdb:AppearedOn rdf:resource="#{@id}"/>
					</imdb:RealPerson>
					<imdb:Title rdf:about="#{@id}">
						<imdb:Release><xsl:value-of select="@year"/></imdb:Release>
						<imdb:Name><xsl:value-of select="@name"/></imdb:Name>
					</imdb:Title>
				</xsl:for-each>
				
				<xsl:for-each select="Person/Filmography/Directing/Movie">
					<imdb:RealPerson rdf:about="#{../../../@id}">
						<imdb:AppearedOn rdf:resource="#{@id}"/>
					</imdb:RealPerson>
					<imdb:Title rdf:about="#{@id}">
						<imdb:Release><xsl:value-of select="@year"/></imdb:Release>
						<imdb:Name><xsl:value-of select="@name"/></imdb:Name>
					</imdb:Title>
				</xsl:for-each>
			</xsl:if>
		</xsl:when>

		<xsl:when test="local-name(child::*[1])='Title'">
			<imdb:Title rdf:ID="{Title/@id}">
				<imdb:Release>
				<xsl:value-of select="Title/Release"/>
				</imdb:Release>
				<imdb:Name>
				<xsl:value-of select="Title/Name"/>
				</imdb:Name>
				<imdb:Rating>
				<xsl:value-of select="Title/Rating"/>
				</imdb:Rating>
			</imdb:Title>
			
			<imdb:RealPerson rdf:about="#{Title/DirectedBy/@id}">
					<imdb:DirectedOn rdf:resource="#{Title/@id}"/>
			</imdb:RealPerson>
			
			<imdb:RealPerson rdf:about="#{Title/DirectedBy/@id}">
					<imdb:Name rdf:resource="#{Title/DirectedBy/@name}"/>
			</imdb:RealPerson>
			
			<imdb:RealPerson rdf:about="#{Title/Cast/Leading/Actor/@id}">
				<imdb:Name>
					<xsl:value-of select="Title/Cast/Leading/Actor/@name"/>
				</imdb:Name>
				<imdb:LeadOn rdf:resource="#{Title/@id}"/>
			</imdb:RealPerson>
			
			<imdb:FictionalPerson rdf:about="#{Title/Cast/Leading/Character/@id}">
				<imdb:Name>
					<xsl:value-of select="Title/Cast/Leading/Character/@name"/>
				</imdb:Name>
				<imdb:AppearedOn rdf:resource="#{Title/@id}"/>
			</imdb:FictionalPerson>
			
			<xsl:for-each select="Title/Cast/Member">
				<imdb:RealPerson rdf:about="#{Actor/@id}">
					<imdb:Name>
					<xsl:value-of select="Actor/@name"/>
				</imdb:Name>
					<imdb:ActedOn rdf:resource="#{../../@id}"/>
				</imdb:RealPerson>
			
				<imdb:FictionalPerson rdf:about="#{Character/@id}">
					<imdb:Name>
					<xsl:value-of select="Character/@name"/>
				</imdb:Name>
					<imdb:AppearsOn rdf:resource="#{../../@id}"/>
				</imdb:FictionalPerson>
			</xsl:for-each>
			
		</xsl:when>
	</xsl:choose>
	</xsl:for-each>
	
</rdf:RDF>

</xsl:template>

</xsl:stylesheet>
